package com.sunsys;

import java.io.IOException;
import java.sql.Connection;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Registration
 */
@WebServlet("/Registration")
public class Registration extends HttpServlet {

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			
			DBConnection connection = new DBConnection();
			Connection con = connection.makeDBConnection();

			PreparedStatement ps = con.prepareStatement("insert into users(username,password,email)values(?,?,?)");
			
			String name = request.getParameter("username");
			String password = request.getParameter("password");
			String email = request.getParameter("Email");
			System.out.println("Email:"+email);
			
			ps.setString(1, name);
			ps.setString(2, password);
			ps.setString(3, email);
			
			int rows = ps.executeUpdate();
			System.out.println(rows+"effected");
			out.println("Successfully Registered");
			
			ps.close();
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		
	}
	
}
